home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 February / Gamestar_81_2006-02_dvd.iso / Red Shark / Common / GermanParatrooper.script < prev    next >
Encoding:
Text File  |  2001-11-14  |  9.3 KB  |  336 lines

  1. //-------------------------------------------------------------------
  2. //
  3. //  This code is copyright 2001 by G5 Software.
  4. //  Any unauthorized usage, either in part or in whole of this code
  5. //  is strictly prohibited. Violators WILL be prosecuted to the
  6. //  maximum extent allowed by law.
  7. //
  8. //-------------------------------------------------------------------
  9.  
  10. class CGermanParatrooperMesh
  11. {
  12.   string MeshFile = "Models/Paratrooper.mesh";
  13.   string SkinFile = "Models/Paratrooper.skin";
  14. }
  15.  
  16. class CParatrooperCollisionDetector
  17. {
  18.   float CollisionRadius = 10.0f;
  19. }
  20.  
  21. class CGermanParatrooperStateControl extends CUnitLifeControl
  22. {
  23.   void CGermanParatrooperStateControl()
  24.   {
  25.     CUnitLifeControl(30.0);
  26.     m_DestroyPause = 0.0;
  27.     m_ExplosionId  = "";
  28.   }
  29.  
  30.   void OnCollisionOccured(
  31.       float _fPower
  32.     )
  33.   {
  34.     // Destroy object
  35.     Core_PostEventTo(
  36.         SOID_MissionController,
  37.         "DestroyGameObject",
  38.         Core_GetIdentificator()
  39.       );
  40.  
  41.     // register paratrooper landing
  42.     Core_PostEventTo(
  43.         SOID_MissionController,
  44.         "ParatrooperLanded",
  45.         Core_GetIdentificator()
  46.       );
  47.   }
  48.  
  49.   void DestroyComponent()
  50.   {
  51.     // Destroy object
  52.     Core_PostEventTo(
  53.         SOID_MissionController,
  54.         "DestroyGameObject",
  55.         Core_GetIdentificator()
  56.       );
  57.  
  58.     // register paratrooper death
  59.     Core_PostEventTo(
  60.         SOID_MissionController,
  61.         "ParatrooperKilled",
  62.         Core_GetIdentificator()
  63.       );
  64.   }
  65. }
  66.  
  67. class CGermanParatrooperGun extends CBaseWeaponDescriptor
  68. {
  69.   int    AmmoQuantity      = -1;
  70.   float  BulletSpeed       = 600.0;
  71.   float  FireDeviation     = 0.02;
  72.   string LinkJointName     = "";
  73.  
  74.   string WeaponName        = "Gun";
  75.   float  FireWeaponDelay   = 0.1;
  76.   bool   IsAutotargeting   = false;
  77.   int    AttachSlotNumber  = 1;
  78.  
  79.   string BulletPatternId   = "BULLETID_GermanParatrooperBullet";
  80.   string EffectOnFire      = "EFFECTID_GunTowerGunFireEffect";   //#TMP
  81.   string SoundOnFire       = "SOUNDID_GunTowerGunFireSound";     //#TMP
  82. }
  83.  
  84. class CGermanParatrooperBehavior extends
  85.     CBaseBehavior, CGermanParatrooperFireParameters
  86. {
  87.   bool CanMove = false;
  88.  
  89.   void CGermanParatrooperBehavior()
  90.   {
  91.     CBaseBehavior();
  92.   }
  93. }
  94.  
  95. class CGermanParatrooperFireParameters
  96. {
  97.   bool CanFire = true;
  98.  
  99.   int  FirePeriod        = 100; // ms
  100.   int  FirePeriodRandAdd = 0; // ms
  101.   int  ShootGunNum       = 1;
  102.  
  103.   bool BurstFire         = true;
  104.   int  BurstTime         = 200; // ms
  105.   int  BurstTimeRandAdd  = 0; // ms
  106.  
  107.   int  BurstDelay        = 5000; // ms
  108.   int  BurstDelayRandAdd = 5000; // ms
  109.  
  110. // radar
  111.  
  112.   bool  HasRadar = true;
  113.  
  114.   float MaxRadarDistance = 1500; // m
  115.   float MinRadarDistance = 30;   // m
  116.  
  117.   int   UpdateRadarPeriod        = 3000; // ms
  118.   int   UpdateRadarPeriodRandAdd = 1000; // ms
  119.  
  120.   bool  FireFlying = true;
  121.   bool  FireGround = true;
  122. };
  123.  
  124. class CParatrooperFreeFallControl extends CWorldPhysics
  125. {
  126.   void CParatrooperFreeFallControl()
  127.   {
  128.     SetFreeFallSpeed(vector(0.0, 0.0, -5.0));
  129.     SetFreeFallAccel(vector(0.0, 0.0,  0.0));
  130.     SetFreeFallAngle(0.0, Math_PI * 2.0);
  131.     EnableFreeFall(true);
  132.   }
  133. }
  134.  
  135. class CGermanParatrooper extends
  136.   CBuilding, CUnitWithStateControl, CUnitWithBehavior, CArmedUnit
  137. {
  138.   void CGermanParatrooper()
  139.   {
  140.     InitializeModelAsStatic("CGermanParatrooperMesh");
  141.     CUnitWithStateControl("CGermanParatrooperStateControl");
  142.     CreateStaticWeapon("Weapon", "CGermanParatrooperGun");
  143.     InitializeVehicleBehavior("CGermanParatrooperBehavior");
  144.  
  145.     CreateComponent("FreeFall", "FreeFallControl", "CParatrooperFreeFallControl");
  146.     SetComponentSlaveObject("FreeFall", "Mesh");
  147.  
  148.     CreateComponent("CollisionDetector", "PointCollisionDetector", "CParatrooperCollisionDetector");
  149.     SetComponentPositionable("CollisionDetector", "Mesh");
  150.  
  151.     Core_AddClassificator("German");
  152.     Core_AddClassificator("Paratrooper");        // for cockpit identification
  153.   }
  154. }
  155.  
  156.  
  157. class CGermanParatrooperGenerator
  158. {
  159.   array m_ParatrooperGroupName   = array();
  160.   array m_ParatrooperGroupSize   = array();
  161.   array m_ParatrooperLandedQty   = array();
  162.   array m_ParatrooperKilledQty   = array();
  163.   array m_ParatrooperTargetPos   = array();
  164.   array m_ParatrooperTargetClass = array();
  165.   array m_ParatrooperTargetName  = array();
  166.   array m_ParatrooperSuccessQty  = array();
  167.  
  168.   void GenerateParatroopersGroup(
  169.       string _BaseId,
  170.       int    _Quantity,
  171.       vector _Position,
  172.       float  _Radius,
  173.       float  _Height,
  174.       string _TargetId,
  175.       string _TargetClass,
  176.       int    _SuccessQty
  177.     )
  178.   {
  179.     for (int Paratrooper = 0; Paratrooper < _Quantity; Paratrooper = Paratrooper + 1)
  180.     {
  181.       final float Alpha  = rand(Math_PI);
  182.       final float Radius = rand(0.0, _Radius);
  183.  
  184.       matrix Position = matrix(
  185.           1.0, 0.0, 0.0, Core_GetVectorX(_Position) + Radius * sin(Alpha),
  186.           0.0, 1.0, 0.0, Core_GetVectorY(_Position) + Radius * cos(Alpha),
  187.           0.0, 0.0, 1.0, Core_GetVectorZ(_Position) + float(Paratrooper) * _Height / float(_Quantity),
  188.           0.0, 0.0, 0.0, 1.0
  189.         );
  190.  
  191.       Core_CallFunction(
  192.           SOID_MissionController,
  193.           "CreateComponent",
  194.           _BaseId + "_" + Paratrooper,
  195.           "GameObject",
  196.           "CGermanParatrooper"
  197.         );
  198.  
  199.       Core_CallFunction(
  200.           SOID_MissionController,
  201.           "SetComponentPosition",
  202.           _BaseId + "_" + Paratrooper,
  203.           Position
  204.         );
  205.     }
  206.  
  207.     m_ParatrooperGroupName.addElement(_BaseId);
  208.     m_ParatrooperGroupSize.addElement(_Quantity);
  209.     m_ParatrooperLandedQty.addElement(0);
  210.     m_ParatrooperKilledQty.addElement(0);
  211.     m_ParatrooperTargetPos.addElement(_Position);
  212.     m_ParatrooperTargetClass.addElement(_TargetClass);
  213.     m_ParatrooperTargetName.addElement(_TargetId);
  214.     m_ParatrooperSuccessQty.addElement(_SuccessQty);
  215.   }
  216.  
  217.   void GenerateParatroopers(
  218.       string _BaseId,        // Name of group w/o number
  219.       int    _Quantity,      // Groups amount
  220.       int    _GroupSize,     // Paratroopers in group
  221.       vector _Position,      // point of landing
  222.       float  _Radius,        // Radius
  223.       float  _Height,        // Hight
  224.       string _TargetId,      // Name of unit after landing
  225.       string _TargetClass,   // Class of unit after landing
  226.       int    _SuccessQty,    // Min troopers amount for unit creating
  227.       float  _DistrTime      // Distribution time for paratroopers creation
  228.     )
  229.   {
  230.     for (int Group = 0; Group < _Quantity; Group = Group + 1)
  231.     {
  232.       final float Alpha  = rand(Math_PI);
  233.       final float Radius = rand(0.0, _Radius);
  234.  
  235.       vector Position = vector(
  236.           Core_GetVectorX(_Position) + Radius * sin(Alpha),
  237.           Core_GetVectorY(_Position) + Radius * cos(Alpha),
  238.           Core_GetVectorZ(_Position) + rand(_Height)
  239.         );
  240.  
  241.       Core_ScheduleTask(
  242.           Core_GetIdentificator(),
  243.           OT_SendEventTo,
  244.           float(Group) * _DistrTime / float(_Quantity),
  245.           "GenerateParatroopersGroup",
  246.           _BaseId + "_" + Group,
  247.           _GroupSize,
  248.           Position,
  249.           _Radius / float(_Quantity),
  250.           _Height,
  251.           _TargetId + "_" + Group,
  252.           _TargetClass,
  253.           _SuccessQty
  254.         );
  255.     }
  256.   }
  257.  
  258.   void ParatrooperLanded(
  259.       string ParatrooperId
  260.     )
  261.   {
  262.     for (int Group = 0; Group < m_ParatrooperGroupName.size(); Group = Group + 1)
  263.     {
  264.       if (Core_IsStringStartsWith(ParatrooperId, m_ParatrooperGroupName[Group]))
  265.       {
  266.         m_ParatrooperLandedQty[Group] = m_ParatrooperLandedQty[Group] + 1;
  267.         CheckParatroopersGroup(Group);
  268.         return;
  269.       }
  270.     }
  271.   }
  272.  
  273.   void ParatrooperKilled(
  274.       string ParatrooperId
  275.     )
  276.   {
  277.     for (int Group = 0; Group < m_ParatrooperGroupName.size(); Group = Group + 1)
  278.     {
  279.       if (Core_IsStringStartsWith(ParatrooperId, m_ParatrooperGroupName[Group]))
  280.       {
  281.         m_ParatrooperKilledQty[Group] = m_ParatrooperKilledQty[Group] + 1;
  282.         CheckParatroopersGroup(Group);
  283.         return;
  284.       }
  285.     }
  286.   }
  287.  
  288.   void CheckParatroopersGroup(
  289.       int _Group
  290.     )
  291.   {
  292.     if ((m_ParatrooperLandedQty[_Group] + m_ParatrooperKilledQty[_Group]) != m_ParatrooperGroupSize[_Group])
  293.       return;
  294.  
  295.     if (m_ParatrooperLandedQty[_Group] < m_ParatrooperSuccessQty[_Group])
  296.     {
  297.       Core_CallFunction(
  298.           SOID_MissionController,
  299.           "OnParatrooperGroupLanded",
  300.           false,
  301.           m_ParatrooperTargetName[_Group]
  302.         );
  303.  
  304.       return;
  305.     }
  306.  
  307.     Core_CallFunction(
  308.         SOID_MissionController,
  309.         "CreateComponent",
  310.         m_ParatrooperTargetName[_Group],
  311.         "GameObject",
  312.         m_ParatrooperTargetClass[_Group]
  313.       );
  314.  
  315.     Core_CallFunction(
  316.         SOID_MissionController,
  317.         "SetComponentPosition",
  318.         m_ParatrooperTargetName[_Group],
  319.         matrix(
  320.             1.0, 0.0, 0.0, Core_GetVectorX(m_ParatrooperTargetPos[_Group]),
  321.             0.0, 1.0, 0.0, Core_GetVectorY(m_ParatrooperTargetPos[_Group]),
  322.             0.0, 0.0, 1.0, Core_GetVectorZ(m_ParatrooperTargetPos[_Group]),
  323.             0.0, 0.0, 0.0, 1.0
  324.           )
  325.       );
  326.  
  327.     Core_CallFunction(
  328.         SOID_MissionController,
  329.         "OnParatrooperGroupLanded",
  330.         true,
  331.         m_ParatrooperTargetName[_Group]
  332.       );
  333.   }
  334. }
  335.  
  336.